import Vue from "vue";
import Vuex from "vuex";
import cache from "./modules/cache";
import { nav1, nav3, nav4 } from "../router/index";
Vue.use(Vuex);
export const store1 = {
  state: {
    routes: [],
    user: "",
    tags: [
      {
        path: "/entry/index",
        name: "entry_index",
        meta: {
          icon: "user",
          title: "工作台",
          cache: false,
        },
      },
    ],
    count: 0,
    // judge_callback: false, // 判断是点击导航加载 还是返回加载
  },
  mutations: {
    SET_ROUTES: (state, data) => {
      state.routes = JSON.parse(sessionStorage.getItem("routes"));
    },
    set_user(state, data) {
      state.user = data;
    },
    SET_TAGS: (state, data) => {
      state.tags.push(data);
    },
    fresh_tags: (state, data) => {
      state.tags = data;
    },
    ADD_COUNT: (state, data) => {
      state.count = data;
    },
  },
  actions: {
    ACT_COUNT({ commit }, data) {
      commit("ADD_COUNT", data);
    },
    ACT_ROUTES({ commit, state }, data) {
      state.tags = [
        {
          path: "/entry/index",
          name: "entry_index",
          meta: {
            icon: "user",
            title: "工作台",
            cache: false,
          },
        },
      ];
      if (data === "1") {
        state.routes = nav1;
        return new Promise((resolve, reject) => {
          resolve(state.routes);
        });
      }
      if (data === "3") {
        state.routes = nav3;
        return new Promise((resolve, reject) => {
          resolve(state.routes);
        });
      }
      if (data === "4") {
        state.routes = nav4;
        return new Promise((resolve, reject) => {
          resolve(state.routes);
        });
      }
      if (data === "2") {
        commit("SET_ROUTES");
        return new Promise((resolve, reject) => {
          resolve(state.routes);
        });
      }
    },
  },
  modules: {
    cache,
  },
};
export default new Vuex.Store(store1);
